// udpServer project main.go
package main

import (
	"fmt"
	"net"
)

func main() {
	fmt.Println("udpserver")
	socket, err := net.ListenUDP("udp4", &net.UDPAddr{
		IP: net.IPv4(192, 168, 1,210 ),
		Port: 8080,
	})

	if err != nil {
		fmt.Println("listern ", err)
		return
	}

	defer socket.Close()

	for {
		data := make([]byte, 20)
		read, remoteAddr, err := socket.ReadFromUDP(data)
		if err != nil {
			fmt.Println("read data ", err)
			continue
		}

		fmt.Println(read, remoteAddr)
		fmt.Printf("%s\n", data)
		send_data := []byte("hi client! from 210")
		_, err = socket.WriteToUDP(send_data, remoteAddr)
		if err != nil {
			return
			fmt.Println("send fail!", err)
		}
	}
}